<% frame_name ||= nil %>
<% filter_form_url = params[:user_id].present? ? spree.admin_user_gift_cards_path(params[:user_id]) : spree.admin_gift_cards_path %>

<%= search_form_for @search,
  url: filter_form_url,
  class: "filter-wrap",
  data: {
    controller: "filters dialog",
    filters_url_value: request.url
  } do |f| %>
    <%= hidden_field_tag :frame_name, frame_name if frame_name.present? %>

    <div class="d-flex flex-column flex-lg-row gap-2">
      <%= render 'spree/admin/shared/filters_search_bar', param: :code_i_cont, label: Spree.t(:code) %>
      <%= render "table_filter_dropdown" %>
      <%= button_tag type: 'button', class: 'btn btn-light d-flex align-items-center', data: { action: 'dialog#open' } do %>
        <%= icon "adjustments", class: "mr-1" %>
        <%= Spree.t("admin.filters") %>
      <% end %>
    </div>

  <dialog class="drawer" data-dialog-target="dialog" id="gift-card-filters-drawer">
    <%= drawer_header(Spree.t(:filter), 'dialog') %>
    <div class="drawer-body">
    <% if params[:user_id].blank? %>
      <div class="form-group">
        <%= f.label :users_email_eq, Spree.t(:email) %>
        <%= f.text_field :users_email_eq, class: "form-control", data: {filters_target: :input} %>
      </div>
    <% end %>

    <div class="form-group">
      <%= f.label :batch_prefix_eq, Spree.t('admin.gift_card_batches.prefix') %>
      <%= f.text_field :batch_prefix_eq, class: "form-control", data: {filters_target: :input} %>
    </div>

    <%= render_admin_partials(:gift_cards_filters_partials, f: f) %>
    </div>
    <div class="drawer-footer">
      <%= drawer_discard_button('dialog') %>
      <div class="form-actions">
        <%= turbo_save_button_tag Spree.t(:filter_results) do %>
          <%= icon("search") %>
          <%= Spree.t(:filter_results) %>
        <% end %>
      </div>
    </div>
  </dialog>

  <%= render "spree/admin/shared/filter_badge_template" %>

  <div data-filters-target="badgesContainer" class="filter-badges-container"></div>
<% end %>
